package com.amp.cloud.rabbit.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RabbitConfig
 * @Desc: TODO
 * @Auther: <Bang>
 * @Date: 2020/08/25 14:17
 * @Version: 1.0
 * @Modified By:
 */
@Configuration
@Slf4j
public class RabbitConfig {

//    @Value("${spring.rabbitmq.addresses}")
//    private String hosts;
//
//    @Value("${spring.rabbitmq.username}")
//    private String userName;
//
//    @Value("${spring.rabbitmq.password}")
//    private String password;
//
//    @Value("${spring.rabbitmq.virtual-host}")
//    private String virtualHost;
//
//
//    @Bean
//    public ConnectionFactory connectionFactory(){
//        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
//        cachingConnectionFactory.setAddresses(hosts);
//        cachingConnectionFactory.setUsername(userName);
//        cachingConnectionFactory.setPassword(password);
////        cachingConnectionFactory.setChannelCacheSize(channelCacheSize);
//        //cachingConnectionFactory.setPort(port);
//        cachingConnectionFactory.setVirtualHost(virtualHost);
//        //设置连接工厂缓存模式：
//        cachingConnectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
//        //缓存连接数
//        cachingConnectionFactory.setConnectionCacheSize(3);
//        //设置连接限制
//        cachingConnectionFactory.setConnectionLimit(6);
//        log.info("连接工厂设置完成，连接地址{}"+hosts);
//        log.info("连接工厂设置完成，连接用户{}"+userName);
//        return cachingConnectionFactory;
//    }

    @Bean
    public Queue queue() {
        return QueueBuilder.durable("testQueue").build();
    }

    @Bean
    public Exchange exchange() {
        return ExchangeBuilder.directExchange("test.exchange").build();
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(exchange()).with("test.route").noargs();
    }
}
